package com.venta.autopartes.utils;

import java.sql.DriverManager;
import java.sql.SQLException;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;

public class Connection {
	
	private static final String URL="jdbc:mysql://208.11.220.249:3306/"; //$NON-NLS-1$
	private static final String DB_NAME="ventadeautos"; //"XML_PROJECT";
	private static final String DRIVER_NAME="org.gjt.mm.mysql.Driver";
	private static final String USER_NAME="jolusafe5";
	private static final String PASSWORD= "860523";
	private static final String TIMEOUT="10000";
	private static final String JDBC_VEHICLE_SALES="jdbc/VehicleSalesDB";
	private static final String COMP_ENV="java:comp/env";
	
	public static java.sql.Connection getConnection(){
		java.sql.Connection connection=null;
		
		try{
			//System.out.println(URL + DB_NAME);
			//Class.forName(DRIVER_NAME).newInstance();
			//connection = DriverManager.getConnection(URL + DB_NAME, USER_NAME, PASSWORD);
			
			Context initCtx = new InitialContext();
			Context envCtx = (Context) initCtx.lookup(COMP_ENV);
			DataSource ds = (DataSource)  envCtx.lookup(JDBC_VEHICLE_SALES);
			connection=ds.getConnection();
			
		}catch(SQLException sqlException){
			System.out.println("(Class)Connection - (ErrorType)sqlException");
			sqlException.printStackTrace();
		}catch(Exception exception){
			System.out.println("(Class)Connection - (ErrorType)Exception");
			exception.printStackTrace();
		}
		
		
		
		return connection;
	
	}
	
}
